(define (get-ast node)
   (let*
      (
         (pair-ast ((interaction-environment)'getVariable (string->symbol "#pair-ast")))
         (ast (pair-ast'get node))
      )
      (if (null? ast)
         (error "Argument not a node")
         ast
      )
   )
)

(define (annotate node message . args)
   (let*
      (
         (env (interaction-environment))
         (checker (env'getVariable (string->symbol "#checker")))
         (pair-ast (env'getVariable (string->symbol "#pair-ast")))
         (ast (pair-ast'get node))
      )
      (if (null? ast)
         (error "Argument to annotate must be a node")
         (checker'log (ast'lineNo) (ast'columnNo) message (list->vector args))
      )
   )
)

(define (top-level? node)
   (null? ((get-ast node)'parent))
)

(define (find-first obj lst)
   (if (null? lst)
      ()
      (let ((node (car lst)))
         (if (pair? node)
            (if (eq? (car node) obj)
               node
               (find-first obj (cdr lst))
            )
            (if (eq? node obj)
               node
               (find-first obj (cdr lst))
            )
         )
      )
   )
)

(define (for-all-recursive obj lst fn)
   (for-each
      (lambda (node)
         (when (pair? node)
            (if (eq? (car lst) obj)
               (fn lst)
               (for-all-recursive obj node fn)
            )
         )
      )
      lst
   )
)
